﻿using B.MES.Customer.Application.Application;
using B.MES.Customer.Application.IApplication;
using B.MES.Customer.Domain.DTO;
using B.MES.Customer.Infrastructure.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace B.MES.Customer.Application.Application
{
    public class BaseApplication<T> : IBaseApplication<T> where T : class, new()
    {
        private readonly IBaseRepository<T> _baseRepository;
  

        public BaseApplication(IBaseRepository<T> baseRepository)
        {
            _baseRepository = baseRepository;
        }

        public void Add(List<T> entity)
        {
            _baseRepository.Add(entity);
        }

        public bool Delete(T entity)
        {
            return _baseRepository.Delete(entity);
        }

        public List<T> GetAll()
        {
            return _baseRepository.GetAll();
        }

        public T GetById(object id)
        {
            return _baseRepository.GetById(id);
        }

        public List<T> GetList(Expression<Func<T, bool>> whereExpression)
        {
            return _baseRepository.GetList(whereExpression);
        }

        public PageApiResut<T> GetPage(int page, int size, Expression<Func<T, bool>> whereLambda, bool IsAsc, Expression<Func<T, object>> orderLambda)
        {
            return _baseRepository.GetPage(page, size, whereLambda, IsAsc, orderLambda);
        }

        public bool Insert(T entity)
        {
            return _baseRepository.Insert(entity);
        }

        public bool Update(T entity)
        {
            return _baseRepository.Update(entity);
        }

        public int SaveChanges()
        {
            // 调用 SqlSugar 的 Commit 方法提交更改
            return _baseRepository.SaveChanges();
        }
        //public List<T> BatchDeleteData(List<T> entities)
        //{
        //    return _baseRepository.BatchDeleteData(entities);
        //}
    }
}
